package com.mall.common;

import lombok.Data;
import java.util.List;

/**
 * 分页结果封装
 * 
 * @author Mall Team
 * @param <T> 数据类型
 */
@Data
public class PageResult<T> {
    
    private Long total;        // 总记录数
    private Integer pageNum;   // 当前页码
    private Integer pageSize;  // 每页大小
    private Integer pages;     // 总页数
    private List<T> list;      // 数据列表
    
    public PageResult() {}
    
    public PageResult(Long total, Integer pageNum, Integer pageSize, List<T> list) {
        this.total = total;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.list = list;
        this.pages = (int) Math.ceil((double) total / pageSize);
    }
    
    /**
     * 创建分页结果
     */
    public static <T> PageResult<T> of(Long total, Integer pageNum, Integer pageSize, List<T> list) {
        return new PageResult<>(total, pageNum, pageSize, list);
    }
    
    /**
     * 空结果
     */
    public static <T> PageResult<T> empty(Integer pageNum, Integer pageSize) {
        return new PageResult<>(0L, pageNum, pageSize, null);
    }
}